#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>

pthread_mutex_t con_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t con_ready = PTHREAD_COND_INITIALIZER;
void thread_wait(void);

int
main(int argc, char *argv[])
{
	int start = clock();
	printf("%d\n",start);
	for(int i=0;i<100000;i++)
	{
		i = i+1;
	}
	int end = clock();
	printf("%d\n",end);
	pthread_attr_t attr;
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

	pthread_t pid_wait;
	
	pthread_create(&pid_wait, &attr, (void*(*)(void*))thread_wait, NULL);
	sleep(10);
	pthread_cond_signal(&con_ready);

	int rc = pthread_join(pid_wait, NULL);
	if(0 == rc)
	{
		printf("join success!\n");
	}
	return 0;
}

void thread_wait(void)
{
	pthread_mutex_lock(&con_lock);
	pthread_cond_wait(&con_ready, &con_lock);
	printf("hellow!\n");
	pthread_mutex_unlock(&con_lock);
}
